package com.balabala.gym_goods.controller.admin;

import com.balabala.gym_enum.ResultEnum;
//import com.balabala.gym_goods.pojo.dto.AttributeQueryDto;
import com.balabala.gym_goods.pojo.entity.Attribute;
//import com.balabala.gym_goods.pojo.vo.AttributeQueryVo;
import com.balabala.gym_goods.service.AttributeService;
import com.balabala.gym_goods.service.AttributeService;
import com.balabala.result.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@Api(tags = "商品属性规格表接口")
@RequestMapping("/admin/attribute")
public class AttributeController {

    @Autowired
    private AttributeService attributeService;

    @ApiOperation(value = "查询所有商品属性规格")
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public Result findAll() {
        List<Attribute> attributeList=attributeService.list();
        return Result.ok(attributeList);
    }

    @ApiOperation(value = "根据id查询商品属性规格信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Result find(@PathVariable("id") Long id) {
        return  Result.ok(ResultEnum.GENERALLY_SUCCESS,attributeService.getById(id));
    }


    @ApiOperation(value = "添加商品属性规格值信息")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result add(@RequestBody Attribute attribute) {
        log.info("添加商品分类信息");
        attribute.setCreateTime(new Date());
        attribute.setUpdateTime(new Date());
        return Result.ok(attributeService.save(attribute));
    }

    @ApiOperation(value = "根据id删除商品属性规格信息")
    @RequestMapping (value = "/delete/{id}",method = RequestMethod.GET)
    public Result deleteById(@PathVariable Long id) {
        boolean result=attributeService.removeById(id);
        return Result.judge(result);
    }


    @ApiOperation(value = "修改商品属性规格信息")
    @RequestMapping (value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody Attribute attribute) {
        attribute.setUpdateTime(new Date());
        boolean result=attributeService.updateById(attribute);
        return Result.judge(result);
    }

}
